﻿/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/
/************************************************************************************
* Copyright (c) 2014  All Rights Reserved. 
* CLR版本： 4.0.30319.35317 
* 创建人：  luoshupeng 
* 电子邮箱：luoshupeng@outlook.com 
* 创建时间：8/29/2014 11:46:36 AM 
* 描述： 
* ===================================================================== 
* 修改标记  
* 修改时间：8/29/2014 11:46:36 AM 
* 修改人： luoshupeng 
* 描述：   
************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace VSConverter.WPF
{
    class RelayCommand : ICommand
    {
        readonly Action<object> _execute;
        readonly Predicate<object> _canExecute;

        public RelayCommand(Action<object> Execute, Predicate<object> CanExecute)
        {
            //Initialize class
            if (Execute == null)
            {
                throw new ArgumentNullException("Execute can`t be null.");
            }

            this._execute = Execute;
            this._canExecute = CanExecute;
        }

        public RelayCommand(Action<object> Execute)
            : this(Execute, null)
        {

        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            _execute(parameter);
        }
    }
}
